import { t } from 'i18next'
import Alert from '@/components/Alert'
import requestMeeting, { request } from '@/plugins/axios'
import { FetchMeetingListItem, FetchSimpleMccInfo } from './interface'
import { transMeetingList } from './translator'

export const fetchGetMeetingList = async () =>
	request<{ list: FetchMeetingListItem[] }>({
		url: `/mcc/confs`,
		method: 'get',
	}).then((res) => (res.success && res.list ? transMeetingList(res.list) : undefined))

export const fetchGetSimpleMccInfo = async (meetingMoid: string) =>
	requestMeeting<FetchSimpleMccInfo>({
		url: `/mcc/${meetingMoid}/simple`,
		method: 'GET',
	}).then((res) => {
		if (res.success && res.data) {
			return res.data
		} else {
			Alert(t('操作失败！'))
			return undefined
		}
	})

export const fetchGetNameCardInfo = async (moid: string) =>
	requestMeeting<any>({
		url: `/user/namecard`,
		method: 'get',
		params: {
			moid: moid,
		},
	}).then((res) => {
		if (res.success && res.data) {
			return res.data
		} else {
			return undefined
		}
	})
